#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

void Test1()
{
    int n = 0;
    cin >> n;

    vector<int> v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }

    long long res = 0;
    vector<vector<long long>> dp(n + 1, vector<long long>(2));

    for (int i = 1; i <= n; ++i)
    {
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = dp[i - 1][0] + v[i - 1];
    }
    res = max(dp[n][0], dp[n][1]);

    cout << res << endl;
}

void Test2()
{
    int n = 0, p = 0;
    cin >> n >> p;

    int res = 0;
    vector<int> low(n), up(n);

    for (int i = 0, tmp = 0; i < n; ++i)
    {
        cin >> tmp;
        low[i] = tmp - p;
        up[i] = tmp + p;
    }

    int cnt = 0;
    for (int lf = 0, rg = 0; lf < n && rg < n;)
    {
        if (low[lf] <= up[rg])
        {
            ++cnt;
            ++lf;
            res = max(res, cnt);
        }
        else
        {
            --cnt;
            ++rg;
        }
    }

    cout << res << endl;
}

int main()
{
    Test2();

    return 0;
}